package com.lwx.leetcode.offer.middile;

public class Offer33 {
    int end;//判断是否完全遍历
    public boolean verifyPostorder(int[] postorder) {
        if (postorder == null || postorder.length == 1) return true;
        end = postorder.length - 1;
        build(postorder, Integer.MIN_VALUE, Integer.MAX_VALUE);
        return end < 0;//如果完全遍历，则end < 0;
    }
    private void build(int[] postorder, int min, int max) {
        if (end < 0) return ;//空了，返回
        int rootV = postorder[end];
        if (rootV >= max || rootV <= min) return ;
        end--;
        build(postorder, rootV, max);//右子树
        build(postorder, min, rootV);//左子树
    }
}
